﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<MvcEngineModelItem<ContactSettingsViewModel>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
    <title><%= this.Model.Localize("ContactSettingsPageTitle")%></title>
    <%= Html.GetCssFile(Url.GetModuleCssPath("MvcEngine.Contact.css")) %>
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <%= Html.SuccessNotification("successNotification", Model.Localize("ContactSettingsSuccessNotification"))%>
    <%= Html.ErrorNotification("errorNotification", Model.Localize("ContactSettingsErrorNotification"))%>
    
    <div class="page-title" id="contact-header">
         <h1><%= Model.Localize("ContactSettingsPageHeader")%></h1>
    </div>
    <div class="page-menu">
        <%= Html.UrlActionLink(Model.Localize("SaveLink"), "javascript:void(0);", new { onclick = "Save();" })%>
    </div>
    
    <div id="contact-settings-content">
        <%= Html.Validators<ContactSettings>("moduleSettingsForm")%>
        <% using (Html.BeginForm(Url.Settings(Model.Item.CtrId), new { id = "contactSettingsForm" }))
        {%>
        <%= Html.FormView<ContactSettingsViewModel>(Model.Item).SetAttributes(new { id = "contact-form" }).Items(item =>
            {
                item.For(s => s.EmailSubjectPrefix).SetLabel(Model.Localize("EmailSubjectPrefixLabel")).SetAttributes(new { @class = "txtLong" });
                item.For(s => s.SendTo).SetLabel(Model.Localize("SendToLabel")).SetTemplateControl("TextArea").SetAttributes(new { id = "txtSendTo" });
                item.For(s => s.Email).SetLabel(Model.Localize("EmailFromLabel")).SetAttributes(new { @class = "txtLong" });
                item.For(s => s.SmtpServer).SetLabel(Model.Localize("SmtpServerLabel")).SetAttributes(new { @class = "txtLong" });
                item.For(s => s.SmtpServerPort).SetLabel(Model.Localize("SmtpServerPortLabel")).SetAttributes(new { @class = "txtShort" });
                item.For(s => s.SmtpUserName).SetLabel(Model.Localize("SmtpUserNameLabel")).SetAttributes(new { @class = "txtLong" });
                item.For(s => s.SmtpPassword).SetLabel(Model.Localize("SmtpPasswordLabel")).SetAttributes(new { @class = "txtLong" });
            })%>
        <%= Html.MvcEngineAntiForgeryToken(m => m.AntiForgeryToken) %>
        <%} %>
    </div>
    
      	<script type="text/javascript">

      	    function Save() {
      	        var options = {
      	            success: function(data) {

      	                var json = JSON.parse(data);
      	                $('.notification').hide('fast');

      	                if (json.model != "valid") {
      	                    $('#errorNotification').show('fast');
      	                    var result = "<ul>";
      	                    for (var i in json.errors) {
      	                        result += "<li>" + json.errors[i] + "</li>";
      	                    }
      	                    result += "</ul>";
      	                    $('#errorNotification .notification-msg-content').html(result);
      	                }
      	                else {
   	                        $('#successNotification').show('fast');
      	                }

      	                $('#successNotification').show('fast');
      	            },
      	            error: function (request, textStatus, errorThrown) {
      	                $('.notification').hide('fast');
      	                $('#errorNotification').show('fast');
      	            }
      	        };

      	        $('#contactSettingsForm').ajaxSubmit(options);
      	    }
    
    </script>
    
</asp:Content>
